{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "090ce2a4",
   "metadata": {},
   "source": [
    "## 人脸识别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "275c3dc1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1678711895,d19a9f3e-dea8-4a87-862d-9f8b3d4d243a', 'time_used': 284, 'faces': [{'face_token': '424fbf1fb088a9f1841cc1a11d3a96cb', 'face_rectangle': {'top': 533, 'left': 321, 'width': 546, 'height': 546}}], 'image_id': 'f6lKmYXAm5ZkB2HqPGprrg==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "face++ 人脸识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('messi.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "# 酬载准备\n",
    "payload = {\n",
    "    'api_key':'4kJky2HgIBMQBCY9xyvRQGdTb4kDjFkK',\n",
    "    'api_secret':'Ux9dWCWNBcVVFH44AZ8MwFyXh_U29Za1',\n",
    "    'image_base64':img\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "25ff5eb6",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1678713195,e7a8e517-12ed-4d86-8984-79c9719a6eec', 'time_used': 285, 'faces': [{'face_token': '33754092d41d0922c961831e00bec48b', 'face_rectangle': {'top': 222, 'left': 250, 'width': 254, 'height': 254}, 'attributes': {'gender': {'value': 'Male'}, 'age': {'value': 21}, 'smile': {'value': 99.845, 'threshold': 50.0}, 'headpose': {'pitch_angle': 12.536303, 'roll_angle': -1.7420084, 'yaw_angle': 4.621022}, 'blur': {'blurness': {'value': 0.356, 'threshold': 50.0}, 'motionblur': {'value': 0.356, 'threshold': 50.0}, 'gaussianblur': {'value': 0.356, 'threshold': 50.0}}, 'emotion': {'anger': 0.027, 'disgust': 0.048, 'fear': 0.028, 'happiness': 94.317, 'neutral': 0.511, 'sadness': 0.027, 'surprise': 5.043}, 'facequality': {'value': 85.536, 'threshold': 70.1}, 'beauty': {'male_score': 93.255, 'female_score': 93.992}}}], 'image_id': 'fGzPsv3MnY7oCKfBC3KOSA==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "face++ 人脸识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('whl.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "# 酬载准备\n",
    "payload = {\n",
    "    'api_key':'4kJky2HgIBMQBCY9xyvRQGdTb4kDjFkK',\n",
    "    'api_secret':'Ux9dWCWNBcVVFH44AZ8MwFyXh_U29Za1',\n",
    "    'image_base64':img,\n",
    "    'return_attributes':'gender,age,smiling,headpose,facequality,emotion,blur,beauty'\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
